//
//  MainTabBarController.m
//  BaseAPP
//
//  Created by Evisu on 16/12/8.
//  Copyright © 2016年 evisum. All rights reserved.
//

#import "MainTabBarController.h"
#import "WeChatViewController.h"
#import "ContactViewController.h"
#import "DiscoverViewController.h"
#import "MineViewController.h"
#import "AppDelegate.h"

@interface MainTabBarController ()

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self changeNav];
    
    NSArray *titleArray = @[@"微信",@"通讯录",@"发现",@"我"];
    NSArray *imageArray = @[@"tabbar_mainframe_25x23_",@"tabbar_contacts_27x23_",@"tabbar_discover_23x23_",@"tabbar_me_23x23_"];
    NSArray *selectImageArray = @[@"tabbar_mainframeHL_25x23_",@"tabbar_contactsHL_27x23_@2x",@"tabbar_discoverHL_23x23_",@"tabbar_meHL_23x23_"];
    WeChatViewController *weChatCtrl = [[WeChatViewController alloc]init];
    ContactViewController *contactsCtrl = [[ContactViewController alloc]init];
    DiscoverViewController *discoverCtrl = [[DiscoverViewController alloc]init];
    MineViewController *mineCtrl = [[MineViewController alloc]init];
    NSArray *ctrlArray = @[weChatCtrl,contactsCtrl,discoverCtrl,mineCtrl];
    
    for (NSInteger i = 0; i < titleArray.count; i++) {
        [self setControllersWithController:ctrlArray[i] Title:titleArray[i] ImageName:imageArray[i] SelectImageName:selectImageArray[i]];
    }
}

- (void)setControllersWithController:(UIViewController *)controller Title:(NSString *)title ImageName:(NSString *)imageName SelectImageName:(NSString *)selectImageName{
    
    controller.view.backgroundColor = KBACKGROUND_COLOR;
    controller.title = title;
    controller.tabBarItem.title = title;
    controller.tabBarItem.image = [UIImage imageNamed:imageName];
    controller.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"000000"]} forState:UIControlStateSelected];
    [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithHexString:@"888888"]} forState:UIControlStateNormal];
    UINavigationController *navCtrl = [[UINavigationController alloc]initWithRootViewController:controller];
    [self addChildViewController:navCtrl];
    
}


/**
 *  全局改变Nav
 */
- (void)changeNav{
    
    //设置NavigationBar背景颜色
    [[UINavigationBar appearance] setBarTintColor:HEXColor(@"#171618")];
    //设置NavigationBar文字颜色
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    //设置BarButtonItem字体的颜色
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    //不设置这个无法修改状态栏字体颜色
    [[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
    //字体大小
    [UINavigationBar appearance].titleTextAttributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:19]};
}


@end
